#include "Renderer.h"
#include "RenderData.h"
#include "Effect.h"
#include "TransformationSection.h"
#include "SceneRendererBridge.h"
#include "SceneRendererBridge.h"
#include "EngineFeatures.h"
#include "DiffuseTexturingSection.h"


Renderer::Renderer(SceneRendererBridge * bridge)
{
	this->bridge = bridge;
}


Renderer::~Renderer(void)
{
	effectPool.ClearPool();
}

void Renderer::SetActiveEffect(int effectMask)
{
	if(effectMask != activeEffectMask)
	{
		activeEffect = effectPool.GetEffect(effectMask);
		activeEffectMask = effectMask;
		activeEffect->Apply();
	}

}

void Renderer::PushRenderData(RenderData & rData)
{
	if(activeEffectMask & DIFFUSE_TEXTUREING == DIFFUSE_TEXTUREING)
	{
		DiffuseTexturingSection * diffuse = (DiffuseTexturingSection*)activeEffect->GetSection(DIFFUSE_TEXTUREING);
		diffuse->SetTexture(&rData.diffuseMap);
	}
}

void Renderer::PushWorldMatrix(glm::mat4 worldMatrix)
{
	TransformationSection * transform = activeEffect->GetTransformSection();
	transform->SetWorldMatrix(&worldMatrix);
}

void Renderer::SetUpSceneRelatedData()
{
	TransformationSection * transform = activeEffect->GetTransformSection();
	transform->SetViewMatrix(&bridge->GetActiveCamera()->GenerateViewMatrix());
	transform->SetProjectionMatrix(&bridge->GetActiveCamera()->GenerateProjMatrix());
	
}